﻿var http = require('http');
var querystring = require('querystring');

var shua = function(uid, type, stype, id, count) {
    var post_data = querystring.stringify({
        AreaID : '1',
        Uid : uid,
        Name : '',
        Type : type,
        SubType : stype,
		ID : id,
		Count : count,
		Lock : '0'
    });

    var options = {
        host: '192.168.0.230',
        port: 80,
        path: '/cgi-bin-gm/addaward',
        method: 'POST',
	    headers: {  
            "Content-Type": 'application/x-www-form-urlencoded',  
            "Content-Length": post_data.length  
        }
    };

    var req = http.request(options, function(res) {
        console.log('STATUS: ' + res.statusCode);
        //console.log('HEADERS: ' + JSON.stringify(res.headers));  
        res.setEncoding('utf8');
	    res.on('data', function (chunk) {  
            console.log('BODY: ' + chunk);  
        });
    });

    req.on('error', function(e) {
        console.error("error:"+e);
    });

    req.write(post_data + "\n");
    req.end();
	
};

var zhuang = function(uid, stype, id){
    shua(uid, '3', stype, id, '20');
};

var xunhuan = function(uid, stype, id1, id2){
    for (var i = id1; i <= id2; i++)
    {
        shua(uid, '3', stype, i, '30');
    }
};

var qiuyuan = function(uid, id){
    shua(uid, '6', '1', id, '1');
};

var qiuyuans = function(uid, id){
    var a = 1;
    while(a <= 16){
        shua(uid, '6', '1', id, '1');
        a = a + 1;
    };
};

exports.shua = shua;
exports.xunhuan = xunhuan;
exports.qiuyuan = qiuyuan;
exports.qiuyuans = qiuyuans;